
import $ from 'jquery';

//列表的方法

export const getListData1= (data) => {
    return {type: 'GETLISTS', payload: data};
};

//设置id

export const setNewsId = (data) => {
    return {type: 'SETNEWSID', payload: data};
}

//跳转详情页

export const goToNewDetailFunc = (data) => {
    return {type: 'GOTONEWDETAIL', payload: data};
}

export function goToNewDetail(params){
    return dispatch=>{
        dispatch(goToNewDetailFunc(params));
    }
}

//请求数据列表的方法 
export function fetchList1(limit) {
    return dispatch => {
        return $.ajax({
            url:"http://10.31.160.71:3000/news/list",
            method:"post",
            data:{rows:limit}
        }).then(data => {  
            dispatch(getListData1(data))
        })
    }
}
export const login=(data)=>{
    return {
        type:'LOGIN',
        payload:data
    }
}
export const toLogin=(data)=>{
    return {
        type:'TOLOGIN',
        payload:data
    }
}
export const getListData=(data)=>{
    return {
        type:'GETPRODUCTLISTS',
        payload:data
    }
}
export function  fetchList(params={page:1}) {
    return dispatch=>{
        var url='http://10.31.160.71:3000/product/list';
        return fetch(url,{method: 'POST'}).then(res=>{
            return res.json();
        }).then(data=>{
            console.log(data);
            dispatch(getListData(data));
        })
    };
}
export const increase2 =() =>{
    return{
        type:'TITLE2',
        payload:data
    };
};

export const decrease2 =() =>{
    return{
        type:'DESC2',
        payload:data
    };
};

export const getListData2= data =>{
    return{
        type:'GETLISTS2',
        payload:data
    };
};

export function fetchList2(){
    // console.log('fetchList is using')
    return dispatch =>{
        var url="http://10.31.160.71:3000/news/list";
        return fetch(url,{method:'post'})
        .then(res =>{
            return res.json();
        }).then(data =>{
            // console.log(data)
            dispatch(getListData2(data));
        });
    };
}

export const pcomments= data =>{
    return{
        type:'PCOMMENTS',
        payload:data
    };
};
export const setComment= data =>{
    return{
        type:'SETCOMMENTS',
        payload:data
    };
};